Skip to content

Update: re-harvest qwen3_14b_decode and scale it to all 40 layers - #1506

Merged
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/issue-1484-qwen3-decode-reharvest
Jul 27, 2026
Merged

Update: re-harvest qwen3_14b_decode and scale it to all 40 layers#1506
ChaoWao merged 1 commit into
hw-native-sys:mainfrom
ChaoWao:fix/issue-1484-qwen3-decode-reharvest

Conversation

@ChaoWao

@ChaoWao ChaoWao commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1484.

What

Re-harvests examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/ from
pypto-lib 45be52c and scales it from a 2-layer chunk to all 40 Qwen3-14B
decode layers in one dispatch
.

Two commits: the CALLABLE include-dirs hook the harvest needs, then the
harvest itself.

Settling the issue's open question

The issue asked whether to run 40 layers as one fused chunk or as 5 dispatches
of the upstream chunk-8, and recommended the latter to keep codegen size down.
That reason does not hold. The generated orchestration loops over layers —
for (int64_t i = 0; i < 40; i += 1) — so going 2 → 40 moves a trip count and
leaves the kernel set the same size. One dispatch it is.

The lib chunks because a 40-layer dispatch used to exceed a 2000 ms stream-sync
timeout (decode_fwd.py:1153). simpler raised that to 50 s in #1175 and a
40-layer step is ~40 ms, so the constraint is gone.

Two other framings in the issue turned out not to apply: @scene_test(level=)
is the runtime hierarchy level (L2 chip vs L3 worker), not a CI cost tier, and
layer count is baked into the orchestration .cpp, so it cannot be a per-CASES
param — one layer count per class.

What actually changed: attention is no longer codegen

Since pypto-lib #765/#796 the attention stage is a CANN
FusedInferAttentionScore extern
, not generated kernels. It folds per-head
QK-norm, RoPE, the paged KV write, the flash inner loop and the online softmax
into one mixed AIC+2×AIV task behind an FFTS barrier.

  • Seven kernels disappear: rope_qkv, qk_gamma, qk_recip,
    fa_work_build, fa_fused_aic/_aiv, online_softmax, attn_fence.
  • The extern arrives under kernels/paged_attention_cce/, copied verbatim.
    kernel/fai_body.hpp reaches its dependencies by relative include, so
    splitting the tree would mean patching the source and re-patching on every
    refresh. Its vendor/ subtree is CANN source under Huawei copyright
    (~16k LOC). Verbatim also means our header/format/language lint must leave it
    alone — hence the carve-out in .pre-commit-config.yaml and
    tests/lint/check_headers.py.
  • Paged KV moves from NSND to vLLM's BSND ([page, token, kv_head, dim], so
    slot_mapping is directly the row index). The golden models the new layout on
    both the attention read and the KV write-back.
  • Building it needs CANN devkit headers, which is what the first commit's
    CALLABLE["incores"][i]["extra_include_dirs"] is for. $ASCEND_HOME_PATH
    keeps them off machine-specific paths.

This depends on #1497 — AscendC's block-local globals carry relocations no
amount of inlining removes, so these kernels could not load before it.

Issue item 3: the hand-edit is gone

The previous harvest patched fa_fused_aiv to replace a [[block_local]] static the loader rejected. That kernel no longer exists and the current
codegen emits no such construct, so this harvest is unmodified codegen
throughout
— a refresh is now a plain copy.

Verification

  • On device: PASSES. Output and all 40 layers' KV caches match the torch
    reference at RTOL=5e-2 / ATOL=1e-1. ~5 min wall on an idle die.
  • No ring-sizing overrides needed. Each layer's intermediates live inside
    that iteration's scope, so the live set does not grow with layer count — the
    default heap / task window / dep pool carry the 40-layer graph.
  • Footprint 38.05 GiB (24.61 weights + 13.44 paged KV, bf16) against 64 GiB
    HBM, matching the issue's estimate.
  • a2a3 onboard sweep: 52 PASS / 0 FAIL. a2a3sim: 60 PASS / 0 FAIL.
    Python UTs: 829 passed, 2 skipped. Full pre-commit clean on the diff.

Docs

README records the exact pypto-lib commit plus the ptoas/pto-isa pins and a
regeneration recipe that works (codegen_only=True, no device). Also updated:
multi-repo-qwen-setup Path 0, docs/testing.md for the new key.

The l0-swimlane docs used this example as their "real SPMD workload", shrinking
the generated fa_fused via --set-arg 0=96. The extern takes its work
distribution from runtime tiling metadata, so no --set-arg shrinks it — those
references are removed rather than repointed at something unverified. The
dfx buffer-capacity row measured at 2 layers is dropped for the same reason.

Notes for review

  • One deliberate deviation from kernel_config.py: it marks k_cache/v_cache
    as plain inputs, but the extern writes the current token's KV into them. The
    CALLABLE marks them INOUT so simpler copies the pools back and the golden
    can verify all 40 layers' KV writes — the stronger check the issue asks for.
  • The diff is large (~30k lines) because of the vendored CANN tree; the
    hand-written surface is the test file, the golden, and the lint carve-outs.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 108 files, which is 8 over the limit of 100.

To get a review, narrow the scope:
• coderabbit review --committed # exclude uncommitted changes
• coderabbit review --dir # limit to a subdirectory
• coderabbit review --base # compare against a closer base

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c88a43a5-e07c-4e58-8c2f-737ed550b432

📥 Commits

Reviewing files that changed from the base of the PR and between 4d3b6da and 370d108.

⛔ Files ignored due to path filters (1)
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/generated/kernel_tiling/kernel_tiling.h is excluded by !**/generated/**
📒 Files selected for processing (123)
  • .claude/skills/l0-swimlane/SKILL.md
  • .claude/skills/multi-repo-qwen-setup/SKILL.md
  • .github/workflows/ci.yml
  • .pre-commit-config.yaml
  • docs/dfx/dfx-buffer-capacity-audit.md
  • docs/dfx/l0-swimlane-profiling.md
  • docs/testing.md
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/README.md
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/down_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/fa_fused_aic.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/gate_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/gate_proj_0.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/gate_proj_1.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/gate_proj_2.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/gate_proj_3.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/gate_proj_4.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/k_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/out_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/out_proj_0.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/q_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/up_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/up_proj_0.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/up_proj_1.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/up_proj_2.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/up_proj_3.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/up_proj_4.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aic/v_proj.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/attn_fence.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/attn_out_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/copy_hidden.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/copy_out.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/dcr_xgamma.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/down_cast_residual.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/down_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/fa_fused_aiv.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/fa_work_build.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/gate_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/kv_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/mlp_out_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/online_softmax.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/out_consolidate.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/out_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/post_rms_reduce.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/q_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/qk_gamma.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/qk_recip.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/residual_rms_cast.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/residual_rms_cast_0.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/residual_rms_cast_1.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/residual_rms_cast_2.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/residual_rms_cast_3.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/rms_recip.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/rope_qkv.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/silu.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/up_seed.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/x_gamma.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/aiv/x_gamma0.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/orchestration/decode_fwd_layers.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/attention/entry.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/attention_rope/entry.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/kernel/fai_body.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/kernel/metadata_layout.h
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/kernel/rope_qkv_generated.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/tiling/entry.cpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/tiling/qwen_fai_runtime_tiler.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/arch/arch.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/arch/cross_core_sync.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/arch/local_tensor_buffer.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/arch/resource.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/base_defs.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/coord.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/detail/alignment.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/detail/dependent_false.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/detail/macros.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/CombineScale.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/block_epilogue.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/block_epilogue_init_outputs.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/block_epilogue_online_softmax.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/block_epilogue_online_softmax_low_prec.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/block_epilogue_rescale_o.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/block/block_epilogue_rescale_o_low_prec.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/dispatch_policy.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/copy_gm_to_ub.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/copy_ub_to_gm.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_broadcast_inplace_by_column.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_broadcast_inplace_by_row.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_broadcast_mul.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_broadcast_one_blk.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_cast.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_copy.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_elemwise_add.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_elemwise_mul.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_elemwise_muls.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/epilogue/tile_common/tile_swizzle.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/block/block_mmad.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/block/block_mmad_pv.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/block/block_mmad_pv_decode.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/block/block_mmad_qk.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/block/block_mmad_qk_decode.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/dispatch_policy.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/gemm_type.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/helper.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_gm_to_l1.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_gm_to_ub.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_l0c_to_gm.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_l1_to_bt.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_l1_to_l0a.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_l1_to_l0b.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/copy_ub_to_gm.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/tile_copy.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/tile_copy_tla.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm/tile_common/tile_mmad.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/gemm_coord.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/layout/layout.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/layout/matrix.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/layout/vector.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/attn_infra/matrix_coord.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/flash_attention_regular.h
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/kernels/vendor/paged_attention_cce/vendor/fused_infer_attention_score/kernel_common.hpp
  • examples/a2a3/tensormap_and_ringbuffer/qwen3_14b_decode/test_qwen3_14b_decode.py
  • simpler_setup/goldens/qwen3_14b_decode.py
  • simpler_setup/scene_test.py
  • tests/lint/check_headers.py

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ChaoWao

ChaoWao commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator Author

CI triage: everything is green except ut on ubuntu/macos, which is not from this PR.

It is test_orphan_child_reaping failing with expected exactly 3 forked sub-worker pids, parent reported [.., .., .., 3] — the test scrapes pids from the parent's combined stdout+stderr, and a resource_tracker: There appear to be 3 leaked shared_memory objects warning contributes a stray digit. #1504 is already fixing exactly this and states that main is currently red on ut because of it. Nothing here touches worker forking or shared memory, and the test passes 5/5 locally.

Will rebase once #1504 lands. Everything else on this run passes, including st-onboard-a2a3 — so the 40-layer case builds its CANN attention extern and runs on real hardware in CI.

@ChaoWao
ChaoWao force-pushed the fix/issue-1484-qwen3-decode-reharvest branch 3 times, most recently from 076aacc to 218f57b Compare July 27, 2026 01:59
Fixes hw-native-sys#1484

The example carried pypto codegen last refreshed on 2026-06-25, cited a
provenance file upstream had deleted (`models/qwen3/14b/decode_layer.py`), and
covered 2 of Qwen3-14B's 40 layers. Re-harvested from `decode_fwd.py`'s
`decode_fwd_layers` at pypto-lib `45be52c` with `_CHUNK_NLAYERS = 40`, and the
README now records that commit plus the ptoas and pto-isa pins so the next drift
is detectable rather than archaeological.

Scaling to the full model is nearly free. The generated orchestration loops over
layers (`for (int64_t i = 0; i < 40; i += 1)`) instead of unrolling them, so
going from 2 to 40 moves a trip count and leaves the kernel set the same size.
The lib chunks its dispatches because a 40-layer one used to exceed a 2000 ms
stream-sync timeout; simpler raised that to 50 s in hw-native-sys#1175 and a 40-layer step is
~40 ms, so the constraint is gone.

What did change is attention. Since pypto-lib hw-native-sys#765 and hw-native-sys#796 it is a CANN
FusedInferAttentionScore extern rather than generated kernels, folding per-head
QK-norm, RoPE, the paged KV write, the flash inner loop and the online softmax
into one mixed AIC+2xAIV task behind an FFTS barrier. Seven kernels go away
(`rope_qkv`, `qk_gamma`, `qk_recip`, `fa_work_build`, `fa_fused_aic`/`_aiv`,
`online_softmax`, `attn_fence`) and the harvested extern arrives under
`kernels/vendor/paged_attention_cce/`.

That extern needs CANN devkit headers, which nothing could express: every incore
compiled against the same fixed include set, even though
`KernelCompiler.compile_incore` has always taken `extra_include_dirs`. The
scene-test `CALLABLE` now carries a per-incore `extra_include_dirs`, resolved
when the kernel is compiled rather than when its module is imported — sim and
macOS runners collect a case declaring a CANN dependency without having CANN.
Entries may use `$VAR` and may name directories that do not exist here, so one
candidate list spans SDK layouts; an unset variable or a set where nothing
survived raises, which beats a "file not found" from four includes deep in
vendored code.

The harvested tree is copied verbatim and must stay that way: `fai_body.hpp`
reaches its dependencies by relative include, and reformatting it would make the
next refresh diff against our copy instead of against upstream — the exact drift
this example exists to expose. It therefore lives under `kernels/vendor/`, and
the repo's header, formatting and language lint skip anything below a `vendor/`
directory. Keying the carve-out on the directory rather than on this operator's
name means the next harvested extern needs no lint change at all.

The extern also moves the paged KV layout from NSND to vLLM's BSND
(`[page, token, kv_head, dim]`, so `slot_mapping` is directly the row index),
which the golden now models for both the attention read and the KV write-back.

The previous harvest needed one hand-edit, replacing a `[[block_local]] static`
in `fa_fused_aiv` that the AICore loader rejected. That kernel no longer exists
and the current codegen emits no such construct, so this harvest is unmodified
codegen throughout.

At 40 layers the case takes ~5 min against a 38.05 GiB fixture (24.61 weights +
13.44 paged KV, bf16) — over half the onboard sweep's 600 s session budget. It
runs as its own CI step on a dedicated device instead, keeping that sweep's short
timeout meaningful as a hang detector.

Verification: passes on device with output and all 40 layers' KV caches matching
the torch reference at RTOL=5e-2 / ATOL=1e-1, with no ring-sizing overrides —
per-layer intermediates live inside that iteration's scope, so the live set does
not grow with layer count.

The l0-swimlane docs used this example as their "real SPMD workload", shrinking
the generated fa_fused via `--set-arg 0=96` on its work-item count. The extern
takes its work distribution from runtime tiling metadata instead, so no
`--set-arg` shrinks it and those references are removed rather than repointed.
The dfx buffer-capacity row measured at 2 layers is dropped for the same reason:
it would now be a stale number rather than a wrong one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ChaoWao
ChaoWao force-pushed the fix/issue-1484-qwen3-decode-reharvest branch from 218f57b to 370d108 Compare July 27, 2026 02:39
@ChaoWao
ChaoWao merged commit dccb837 into hw-native-sys:main Jul 27, 2026
29 of 31 checks passed
@ChaoWao
ChaoWao deleted the fix/issue-1484-qwen3-decode-reharvest branch July 27, 2026 03:19
ChaoWao added a commit to ChaoWao/simpler-fork that referenced this pull request Jul 27, 2026
… dots

`fix-pr` Step 6 told you to squash first and rebase after: the `> 1` row
soft-resets to `$BASE_REF`, and only the following list says "rebase onto
`$BASE_REF`". `commit-and-push` has the opposite (correct) order, so the two
documents disagreed and the skill's order is the one that corrupts the commit.

`git reset --soft "$BASE_REF"` moves HEAD to the base but keeps the branch's
index. If the branch still sits on an older base — which it does whenever
anything merged while the PR was open — every file the base gained meanwhile is
recorded as a deletion by the PR. Rebasing afterwards does not repair it: the
revert is by then part of the PR's own diff and replays cleanly onto the new
base. It surfaces as unrelated files being reverted, easy to miss in a large
diff and easy to merge.

Hit while squashing hw-native-sys#1506: `docs/troubleshooting/device-error-codes.md` came
back as -86 lines because hw-native-sys#1501 had merged since the branch point.

Step 6 now fetches and rebases at the top, *before* the edit step rather than
after it: git refuses to rebase a dirty worktree, so a rebase placed after the
fix cannot run at all. Verification gains a three-dot diff of the file list, and
it lives with the single-commit check after the commit exists — at the
soft-reset itself `HEAD` is `$BASE_REF`, so that diff is empty by construction
and would have verified nothing. Two dots would also list files the base has and
the branch does not, rendering them as the branch's deletions: it both hides a
real revert in the noise and invents fake ones.

The single-commit check now separates its outcomes, since the surrounding table
already treats them differently: `> 1` squashes again, `0` stops.

`commit-and-push` §1 gains the fetch, and its soft-reset step states the
precondition it silently relied on.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ChaoWao added a commit that referenced this pull request Jul 27, 2026
… dots (#1516)

`fix-pr` Step 6 told you to squash first and rebase after: the `> 1` row
soft-resets to `$BASE_REF`, and only the following list says "rebase onto
`$BASE_REF`". `commit-and-push` has the opposite (correct) order, so the two
documents disagreed and the skill's order is the one that corrupts the commit.

`git reset --soft "$BASE_REF"` moves HEAD to the base but keeps the branch's
index. If the branch still sits on an older base — which it does whenever
anything merged while the PR was open — every file the base gained meanwhile is
recorded as a deletion by the PR. Rebasing afterwards does not repair it: the
revert is by then part of the PR's own diff and replays cleanly onto the new
base. It surfaces as unrelated files being reverted, easy to miss in a large
diff and easy to merge.

Hit while squashing #1506: `docs/troubleshooting/device-error-codes.md` came
back as -86 lines because #1501 had merged since the branch point.

Step 6 now fetches and rebases at the top, *before* the edit step rather than
after it: git refuses to rebase a dirty worktree, so a rebase placed after the
fix cannot run at all. Verification gains a three-dot diff of the file list, and
it lives with the single-commit check after the commit exists — at the
soft-reset itself `HEAD` is `$BASE_REF`, so that diff is empty by construction
and would have verified nothing. Two dots would also list files the base has and
the branch does not, rendering them as the branch's deletions: it both hides a
real revert in the noise and invents fake ones.

The single-commit check now separates its outcomes, since the surrounding table
already treats them differently: `> 1` squashes again, `0` stops.

`commit-and-push` §1 gains the fetch, and its soft-reset step states the
precondition it silently relied on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Health] qwen3_14b_decode: re-harvest stale 2-layer codegen and scale the case to 40 layers

1 participant